package com.ww.springboot.sharding.config;

import com.ww.springboot.sharding.entity.OutOrderDetailsEntity;
import com.ww.springboot.sharding.service.IOutOrderDetailsService;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @author wanwei
 * @since 2021-05-03 11:23
 */
@Configuration
@AllArgsConstructor
public class DataInsertTest {


    private final IOutOrderDetailsService detailsService;


    @PostConstruct
    public void start() {
        List<OutOrderDetailsEntity> outOrderDetailsEntities = new ArrayList<>();

        for (int i = 0; i < 10; i++) {
            OutOrderDetailsEntity outOrderDetailsEntity = new OutOrderDetailsEntity();
            outOrderDetailsEntity.setTracknumber(i + UUID.randomUUID().toString());
            outOrderDetailsEntity.setOId(Long.valueOf(i));
            outOrderDetailsEntity.setPaidTime(new Date());
            outOrderDetailsEntity.setOutstockTime(new Date());
            outOrderDetailsEntities.add(outOrderDetailsEntity);
        }
        detailsService.insertOutOrderDetails(outOrderDetailsEntities);
    }

}
